<template>
	<view>
		<view class="">
			<view class="upload" @tap='upload'>
				<image :src="img" mode="" style="width: 64rpx;height: 64rpx;margin-top: 90rpx;"
					v-if="uploadImg===''||type==='mp4'?true:false">
				</image>
				<image :src="uploadImg" mode="" v-if="uploadImg===''||type==='mp4'?false:true"
					style="width: 150rpx;height: 150rpx;margin-top: 90rpx;"></image>
				<br />
				<view class="" style="text-align: center;">
					添加图/视频
				</view>
			</view>

			<view class="" style="text-align: center;">
				<video :src="uploadImg" v-if="type==='mp4'" autoplay=true @error='err'></video>
			</view>

			<view class="">
				问题类型
			</view>
			<view class=""
				style="padding-top: 26rpx;padding-left: 30rpx;padding-bottom: 25rpx;color:  rgba(51,51,51,1);">
				支付功能异常
			</view>
			<view class="">
				问题描述
			</view>
			<textarea name="" id="" cols="30" rows="10" placeholder="请输入问题描述"
				style="width: 690rpx;height: 240rpx;padding-top: 26rpx;padding-left: 30rpx;"></textarea>
			<view class="" style="padding-top: 30rpx;padding-bottom: 30rpx;">
				联系方法
			</view>
			<input type="text" placeholder="请输入联系方法"
				style="padding-top: 26rpx;padding-left: 30rpx;padding-bottom: 25rpx;width: 690rpx;" />

			<button class="btn" @tap="goMy">提交</button>
		</view>

		<view class="mask" v-show="flag">
			<view class="modal">
				<image src="@/static/img/提交.png" mode="" style="width: 280rpx;height: 194rpx;margin-top: 86rpx;">
				</image>
				<view class="" style="margin-top: 61rpx;">
					提交成功
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flag: false,
				img: '../../../../../../static/img/photo.png',
				uploadImg: '',
				type: ''
			}
		},
		methods: {
			goMy() {
				this.flag = true
				// uni.navigateTo({
				// 	url:'/pages/my/my'
				// })

				setTimeout(() => {
					console.log(1);
					uni.switchTab({
						url: '/pages/my/my',
						success() {
							console.log(2);
						},
						fail(err) {
							console.log(err);
						},
						complete() {
							console.log(3);
						}
					})
				}, 2000)
			},
			upload() {
				uni.chooseMedia({
					count: 1,
					mediaType: ['image', 'video'],
					sourceType: ['album', 'camera'],
					camera: 'back',
					success: (res) => {
						const tempFilePaths = res.tempFiles[0].tempFilePath;
						uni.uploadFile({
							url: 'http://47.93.162.7:3000/upload', // 你的上传接口地址
							filePath: tempFilePaths,
							name: 'file', // 这里根据后端需要的字段来定义
							formData: {
								'user': 'test' // 其他要传的参数可以在这里添加
							},
							success: uploadFileRes => {
								let {
									code,
									path
								} = JSON.parse(uploadFileRes.data)
								this.type = path.split('.')[4]
								this.uploadImg = path
								if (this.type === 'mp4') {
									this.uploadImg = tempFilePaths
								}
								// 处理上传成功的结果
							},
							fail: uploadFileError => {
								// 处理上传失败的错误
								console.log(uploadFileError);
							}
						});

					}
				})
			},
			err(e) {
				console.log(e);
			}
		}
	}
</script>

<style>
	page {
		width: 100%;
		/* height: 100vh; */
		padding: 30rpx;
	}

	.upload {
		/* margin-left: 30rpx; */
		width: 689rpx;
		height: 280rpx;
		text-align: center;
		/* display: flex;
	justify-content: center;
	align-items: center; */
	}

	.btn {
		position: absolute;
		bottom: 30rpx;
		left: 30rpx;
		width: 689rpx;
		height: 80rpx;
		background-color: #FFA400;
		color: white;
		line-height: 80rpx;
	}

	.mask {
		width: 100%;
		height: 100vh;
		background-color: rgba(51, 51, 51, 0.3);
		position: absolute;
		top: 0;
		left: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 1000;
	}

	.modal {
		width: 640rpx;
		height: 462rpx;
		background-color: white;
		border-radius: 16rpx;
		text-align: center;
	}
</style>